package com.fancy.learncenter.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.ui.activity.base.BaseActivity;
import com.fancy.learncenter.ui.adapter.FragPagerAdapter;
import com.fancy.learncenter.ui.fragment.CartoonPicSpeakFragment;
import com.fancy.learncenter.ui.view.CartoonCompletePopupWindow;
import com.fancy.learncenter.utils.FileUtils;
import com.fancy.learncenter.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CartoonExpandTrainActivity extends BaseActivity {

    @Bind(R.id.work_title)
    TextView workTitle;
    @Bind(R.id.work_current_num)
    TextView workCurrentNum;
    @Bind(R.id.work_total_num)
    TextView workTotalNum;
    @Bind(R.id.submit)
    LinearLayout submit;
    @Bind(R.id.view_pager)
    ViewPager viewPager;
    @Bind(R.id.left_work)
    ImageView leftWork;
    @Bind(R.id.submit_work)
    ImageView submitWork;
    @Bind(R.id.right_work)
    ImageView rightWork;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCartoonContentView(R.layout.activity_cartoon_expand_train, BaseActivity.Status.STATUS);
        ButterKnife.bind(this);

        List<Fragment> fragments = new ArrayList<>();


        fragments.add(CartoonPicSpeakFragment.newInstance(FileUtils.getExpandRecorderAudioPath()));
//        fragments.add(new CartoonSentenceSpeakFragment("", FileUtils.getExpandRecorderAudioPath()));
        List titles = new ArrayList();
        for (int i = 0; i < fragments.size(); i++) {
            titles.add("");
        }


        workTitle.setText("这里是作业标题");
        workTotalNum.setText("/" + fragments.size());
        FragPagerAdapter mFragmentAdapteradapter =
                new FragPagerAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        viewPager.setAdapter(mFragmentAdapteradapter);

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                workCurrentNum.setText("" + (position + 1));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @OnClick(R.id.submit)
    public void onViewClicked() {
        CartoonCompletePopupWindow cartoonCompletePopupWindow = new CartoonCompletePopupWindow(this);
        cartoonCompletePopupWindow.showPopupWindow();
    }

    @OnClick({R.id.left_work, R.id.submit_work, R.id.right_work})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_work:
                ToastUtil.show("左滑动");
                viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, true);
                break;
            case R.id.submit_work:
                ToastUtil.show("确认提交");
                break;
            case R.id.right_work:
                ToastUtil.show("右滑动");
                viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, true);
                break;
        }
    }
}
